/*立即购买*/
function buyNow(productId, productSkuRelationId) {
	window.location.href = decodeURIComponent(ctx + '/order/buyNow?productId=' + productId + "&productSkuRelId=" + productSkuRelationId);
}

/*加入购物车*/
function addCart(id, name, price, smallImage, productSkuRelationId){
	$.ajax({
		type : 'POST',
		url : ctx + '/shop/addProductToCart.do',
		data : {
			productId : id,
			productName : name,
			smallImage : smallImage,
			price : price,
			productSkuRelId : productSkuRelationId
		},
		dataType : 'json',
		timeout : 30000,
		context : $('body'),
		success : function(data) {
			if (data.code == "ok") {
				var obj = data.object;
				//购物车显示编辑
				$("#edit").html('<a href="' + ctx + '/shop/shoppingCart">编辑</a>');
				//购物车显示数量,总金额
				$("#cartTotalCounts").text(obj.counts);
				$("#cartTotalValue").text("¥"+obj.value.toFixed(2));
				
				//购物车商品及数量显示
				var result = '';
				var items = obj.items;
				for (item in items) {
					item = items[item];
					result += '<div class="media">'
								+'<a class="media-left media-middle" href="' + ctx + '/product/'+item.productId+'">'
								+'<img class="avatar-md" src="'+item.smallImage+'" >'
								+'</a>'
								+'<div class="media-body media-middle">'
								+'<a style="color: #333333" href="' + ctx + '/product/'+item.productId+'" class="productName">'+item.productName+'&nbsp'+item.skuValue1+item.skuValue2+'&nbsp('+item.counts+')</a>'
								+'</div>'
								+'</div>';
					
				}
				$("#cartItemList").html(result);
			} else {
				showTip2(data.msg);
			}
		},
		error : function(xhr, type) {
			showTip2('提交失败!');
		}
	});
}